package com.mycompany.app.webapp.action.person;

import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;

import com.mycompany.app.model.Person;
import com.mycompany.app.webapp.model.Page;
import com.opensymphony.xwork2.Action;

@Results({
	@Result(name=Action.SUCCESS, value="/WEB-INF/pages/person/view.jsp")
})
public class ViewAction extends BaseAction {

	private static final String PAGE_HEADING_RESOURCE_NAME = "person.view.heading";
	private static final String PAGE_TITLE_RESOURCE_NAME = "person.view.title";
	private ViewAction _this = this;
	private Long id;
	private Person person;
	private Page page;

	public void setSeam(ViewAction seam) {
		this._this = seam;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Person getPerson() {
		return person;
	}

	@Override
	public String execute() {
		if (id != null) {
			person = personManager.get(id);

			String title = _this.getText(PAGE_TITLE_RESOURCE_NAME);
			String heading = _this.getText(PAGE_HEADING_RESOURCE_NAME);
			page = new Page(title, heading);
		}
		return SUCCESS;
	}

	public Page getPage() {
		return page;
	}

}
